package com.gemme.gemme.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.gemme.gemme.R;
import com.gemme.gemme.shequ.CommunityBean;

public class GuanzhuItem9View extends RelativeLayout {
    private Context context;
    public GuanzhuItem9View(Context context) {
        this(context,null);
    }

    public GuanzhuItem9View(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public GuanzhuItem9View(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        initView();
    }
    LinearLayout ll_content;
    private void initView() {
        LayoutInflater.from(context).inflate(R.layout.guanzhu_9_item,this);

        ll_content = findViewById(R.id.ll_content);
//        addItem();

    }

    private void addItem() {
        LinearLayout ll = null;
        //0 1 2 3    3
        for (int i = 0; i < 9; i++) {
           if( i % 3 == 0){

               ll = new LinearLayout(context);
               ll_content.addView(ll);
           }

           ll.addView(new GuanzhuItem1View(context));
        }
    }

    public void setData(CommunityBean.DataBean dataBean) {
        try {
            ll_content.removeAllViews();
            String picturePath = dataBean.getPicturePath();
            String[] arr = picturePath.split(",");
            LinearLayout ll = null;
            int length  = arr.length;
            if(length> 9){
                length = 9;
            }
            for (int i = 0; i < length; i++) {
                if( i % 3 == 0){

                    ll = new LinearLayout(context);
                    ll.setWeightSum(3);
                    ll_content.addView(ll);
                }
                GuanzhuItem1View guanzhuItem1View = new GuanzhuItem1View(context);
                guanzhuItem1View.setLayoutParams(new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.0f));
                guanzhuItem1View.setData(arr[i]);
                ll.addView(guanzhuItem1View);
            }
        }catch (Exception e){

        }
    }
}
